//
//  JsInputBoxVm.m
//  DuTe
//
//  Created by Gikki Ares on 2020/12/22.
//  Copyright © 2020 vgemv. All rights reserved.
//

#import "JsInputBoxVm.h"
#import <JsUtilitySdk/JsGeometryManager.h>
@interface JsInputBoxVm()

@property (nonatomic,assign)CGFloat mf_x_tv;
@property (nonatomic,assign)CGFloat mf_y_tv;
@property (nonatomic,assign)CGFloat mf_w_tv;
@property (nonatomic,assign)CGFloat mf_h_tv;


@end

@implementation JsInputBoxVm

+ (JsInputBoxVm *)defaultInstance {
	JsInputBoxVm * vm = [JsInputBoxVm new];
	return vm;
}


- (instancetype)init {
	self = [super init];
	if (self) {
		[self commonInit];
	}
	return self;
}

- (void)commonInit {
	//定义一些不变的量
	self.mf_width = [[UIScreen mainScreen] bounds].size.width;
	self.mf_height = 100;
	
	
	self.mf_leading_tv = 15;
	self.mf_trailing_tv = 15;
	self.mf_top_tv = 15;
	
	//字体颜色.
	self.mcolor_text = [UIColor blackColor];
	self.mcolor_placeHolder = [UIColor lightGrayColor];
	//textView字体大小
	self.mfont_text = [UIFont systemFontOfSize:18];
	self.mf_top_text = 8;
	self.mf_bottom_text = 8;
	self.mf_maxHeight_text = 75;
	
//	self.mstr_placeHolder = @"写评论";
	self.mf_leading_placeHolder = 6;
	
	
	self.mf_x_tv = self.mf_leading_tv;
	self.mf_y_tv = self.mf_top_tv;
	self.mf_w_tv = self.mf_width - self.mf_leading_tv - self.mf_trailing_tv;
	
	self.mf_spacing_tv_btn = 0;
	self.mf_leading_expression = 10;
	self.mf_w_expression = 30;
	self.mf_h_expression = 50;
	
	self.mf_w_publish = 67;
	self.mf_h_publish = 31;
	self.mcolor_publish_textEmpty = [UIColor lightGrayColor];
	self.mcolor_publish_textNotEmpty = [UIColor redColor];
	
}

#pragma mark 3 Interface
- (void)doCaculate {
	//计算会改变的量
	NSString * str = self.mstr_text;
	if(!str.length) {
		str=self.mstr_placeHolder;
	}

	//实际的文本绘制区域,比TextView的宽度要小.这里减去一个8的偏差.
	CGFloat textAreaWidth = self.mf_w_tv - 8;
	CGSize size = [str boundingRectWithSize:CGSizeMake(textAreaWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.mfont_text} context:nil].size;
	
	
	if(size.height<self.mf_maxHeight_text) {
		self.mf_height_text = size.height;
	}
	else {
		self.mf_height_text = self.mf_maxHeight_text;
	}
	
	self.mf_h_tv = self.mf_top_text + self.mf_bottom_text + self.mf_height_text;
	
	//自身的高度是一个可变的量
	self.mf_height = self.mf_top_tv + self.mf_h_tv + self.mf_spacing_tv_btn + self.mf_h_expression;
}



- (CGRect)riseFrame {
	CGFloat y = [UIScreen mainScreen].bounds.size.height - self.mf_keyboardHeight - self.mf_height;
	return CGRectMake(0,y,self.mf_width,self.mf_height);
}

- (CGRect)downFrame {
	CGFloat y = [UIScreen mainScreen].bounds.size.height - self.mf_height;
	return CGRectMake(0,y,self.mf_width,self.mf_height);
}

//自身的frame
- (CGRect)frame {
	if(self.mb_isRised) {
		return [self riseFrame];
	}
	else {
		return [self downFrame];
	}
}

- (CGRect)bounds {
	return CGRectMake(0,0,self.mf_width,self.mf_height);
}
- (CGRect)placeholdLabelFrame {
	return CGRectMake(self.mf_x_tv+self.mf_leading_placeHolder, self.mf_y_tv+self.mf_top_text, self.mf_w_tv, self.mf_height_text);
}
- (CGRect)textFrame {
	return CGRectMake(self.mf_x_tv, self.mf_y_tv+self.mf_top_text, self.mf_w_tv, self.mf_height_text);
}
- (CGRect)textViewFrame {
	return CGRectMake(self.mf_x_tv, self.mf_y_tv, self.mf_w_tv,self.mf_h_tv);
}

//ExpressionBtnFrame
- (CGRect)expressBtnFrame {
	CGFloat x = self.mf_leading_expression;
	CGFloat y = self.mf_y_tv + self.mf_h_tv + self.mf_spacing_tv_btn;
	CGFloat w = self.mf_w_expression;
	CGFloat h = self.mf_h_expression;
	return CGRectMake(x,y,w,h);
}

//VoiceButtonFrame
- (CGRect)voiceBtnFrame {
	CGRect expressionFrame = [self expressBtnFrame];
	CGFloat x = expressionFrame.origin.x + expressionFrame.size.width + 10;
	CGFloat y = expressionFrame.origin.y;
	CGFloat w = self.mf_w_expression;
	CGFloat h = self.mf_h_expression;
	return CGRectMake(x,y,w,h);
}
- (CGRect)publishBtnFrame {
	CGRect expressionFrame = [self expressBtnFrame];
	CGFloat x = self.mf_width - self.mf_w_publish - self.mf_trailing_tv;
	CGFloat y = expressionFrame.origin.y + (expressionFrame.size.height - self.mf_h_publish)/2;
	CGFloat w = self.mf_w_publish;
	CGFloat h = self.mf_h_publish;
	return CGRectMake(x, y, w, h);
}



@end
